package com.safeneeds.linguimana.ser.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.safeneeds.linguimana.dto.OndutyDataStorePort;
import com.safeneeds.linguimana.entity.EntityPortGlutOnduty;
import com.safeneeds.linguimana.entity.PortGlutOnduty;
import com.safeneeds.linguimana.entity.dao.IPortGlutDutyDao;
import com.safeneeds.linguimana.entity.dao.IPortGlutNoticeDao;
import com.safeneeds.linguimana.ser.IBgDutyService;
import com.safeneeds.util.base.RetType;
import com.safeneeds.util.date.DateUtil;
import com.safeneeds.util.other.StringUtil;
import com.safeneeds.util.page.PageInfo;
import com.safeneeds.util.page.ser.IPageService;

@Service
@Transactional
public class BgDutyService implements IBgDutyService{

	/**
	 * 今日值班
	 * @author ytw
	 *
	 */
	@Resource(name="portGlutDutyDao")
	private IPortGlutDutyDao portGlutDutyDao;
	@Resource(name="pageService")
	private IPageService pageService;
	
	@Override
	public List<PortGlutOnduty> getDuty() {
		
		List<PortGlutOnduty> list=portGlutDutyDao.getDuty();
		
		return list;
	}
	@Override
	public PageInfo listOndutyPage(PageInfo pageInfo,
			OndutyDataStorePort ondutyDataStorePort) {
		// TODO Auto-generated method stub
		
		pageInfo = portGlutDutyDao.listOndutyPageDao(pageInfo,ondutyDataStorePort);
		pageInfo = pageService.getSQLPageInfo(pageInfo);
		return pageInfo;
	}

	@Override
	public RetType addOrUpdateOnduty(EntityPortGlutOnduty entityPortGlutOnduty) {
		// TODO Auto-generated method stub
		//新增
		if(StringUtil.isEmpty(entityPortGlutOnduty.getOndutyId())){
			PortGlutOnduty newonduty = new PortGlutOnduty();
			newonduty.setDutyphone(entityPortGlutOnduty.getDutyphone());
			newonduty.setLeader(entityPortGlutOnduty.getLeader());
			newonduty.setLeaderPhone(entityPortGlutOnduty.getLeaderPhone());
			newonduty.setName(entityPortGlutOnduty.getName());
			newonduty.setTelephone(entityPortGlutOnduty.getTelephone());
			newonduty.setTime(DateUtil.parseDateYMDStringTest(entityPortGlutOnduty.getTime()));
			portGlutDutyDao.addOndutyDao(newonduty);
		//更新
		}else{
			PortGlutOnduty newonduty = new PortGlutOnduty();
			newonduty.setOndutyId(entityPortGlutOnduty.getOndutyId());
			newonduty.setDutyphone(entityPortGlutOnduty.getDutyphone());
			newonduty.setLeader(entityPortGlutOnduty.getLeader());
			newonduty.setLeaderPhone(entityPortGlutOnduty.getLeaderPhone());
			newonduty.setName(entityPortGlutOnduty.getName());
			newonduty.setTelephone(entityPortGlutOnduty.getTelephone());
			newonduty.setTime(DateUtil.parseDateYMDStringTest(entityPortGlutOnduty.getTime()));

			portGlutDutyDao.saveOrUpadateOnduty(newonduty);
		}
		RetType reType = new RetType();
		reType.setErrCode(RetType.RET_SUCCESS);
		
		return reType;
	}
	@Override
	public EntityPortGlutOnduty getportGlutOnduty(String ondutyId) {
		// TODO Auto-generated method stub
		PortGlutOnduty onduty = portGlutDutyDao.getOndutyByOndutyId(ondutyId);
		EntityPortGlutOnduty entityOnduty = new EntityPortGlutOnduty();
		entityOnduty.setDutyphone(onduty.getDutyphone());
		entityOnduty.setLeader(onduty.getLeader());
		entityOnduty.setLeaderPhone(onduty.getLeaderPhone());
		entityOnduty.setName(onduty.getName());
		entityOnduty.setOndutyId(onduty.getOndutyId());;
		entityOnduty.setTelephone(onduty.getTelephone());
		entityOnduty.setTime(DateUtil.getDateByYMDnormal(onduty.getTime()));
		return entityOnduty;
	}
	@Override
	public RetType deleteOndutyById(String ids) {
		// TODO Auto-generated method stub
		RetType retType = new RetType();
		portGlutDutyDao.deleteOndutyByIdDao(ids);
		retType.setErrCode(RetType.RET_SUCCESS);
		return retType;
	}
	

}
